package com.example.statistics.utils.file


fun String.isImage(): Boolean {
    return FileType.type(this) == FileType.IMAGE
}

fun String.isPDF(): Boolean {
    return FileType.type(this) == FileType.PDF
}

fun String.isWord(): Boolean {
    return FileType.type(this) == FileType.WORD
}

fun String.isExcel(): Boolean {
    return FileType.type(this) == FileType.EXCEL
}

fun String.isPPT(): Boolean {
    return FileType.type(this) == FileType.PPT
}

fun String.isTXT(): Boolean {
    return FileType.type(this) == FileType.TXT
}

fun String.isVIDEO(): Boolean {
    return FileType.type(this) == FileType.VIDEO
}

private object FileType {

    val IMAGE = "image"
    val VIDEO = "video"
    val PDF = "pdf"
    val WORD = "word"
    val EXCEL = "excel"
    val PPT = "ppt"
    val TXT = "txt"
    val UNKNOWN = "unknown"

    fun type(name: String): String {
        val suffix = name.fileSuffix
        return when (suffix) {
            ".png", ".PNG", ".jpg", ".jpeg", ".JPEG", ".WEBP", ".bmp", ".BMP", ".webp" -> IMAGE
            ".mp4", ".MP4" -> VIDEO
            ".doc", ".docx" -> WORD
            ".xls", ".xlsx" -> EXCEL
            ".ppt", ".pptx" -> PPT
            ".pdf", ".PDF" -> PDF
            ".txt" -> TXT
            else -> UNKNOWN
        }
    }
}